package net.int0r.gscore.connector;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.json.JSONArray;

import net.int0r.gscore.gobjects.Spot;
import net.int0r.gscore.util.GJSONObject;
import net.int0r.gscore.util.GowallaConnector;

public class TopSpotsConnector {
	public static ArrayList<Spot> getTopSpots(String userName) {
		ArrayList<NameValuePair> urlParms = new ArrayList<NameValuePair>();
		GJSONObject jsobj = GowallaConnector.getJSONObj(urlParms, "/users/"+userName+"/top_spots");
		ArrayList<Spot> topSpots = new ArrayList<Spot>();
		if(!jsobj.isNull("top_spots")) {
			try {
				JSONArray jspts = jsobj.getJSONArray("top_spots");
				for(int i=0; i<jspts.length(); i++) {
					Spot tmpSpot = new Spot(new GJSONObject(jspts.get(i).toString()));
					System.out.println(tmpSpot);
					topSpots.add(tmpSpot);
				}
			}
			catch(Exception ex) {
				ex.printStackTrace();
			}
		}
		return topSpots;
	}
}
